package com.highspeed.bdk.gateway.socket.analyze.preset.deploy.request.issued.instruction;

import com.highspeed.bdk.gateway.Util;
import com.highspeed.bdk.gateway.socket.analyze.preset.deploy.request.issued.base.DisplayType;

import java.util.Date;

/**
 * RIO链路APP信息调显指令
 */
public class AppDisplayInstruction {
    public byte[] createdInstruction(short srcLogicalId, short destLogicalId, short markAddr, DisplayType displayType) {
        byte[] bytes = new byte[60];
        int len = bytes.length;
        int offset = 0;
        //帧头
        Util.putInt(bytes, 0x55555555, offset);
        offset += 4;

        //消息长度
        Util.putInt(bytes, len, offset);
        offset += 4;

        //源逻辑ID
        Util.putShort(bytes, srcLogicalId, offset);
        offset += 2;

        //目的逻辑ID
        Util.putShort(bytes, destLogicalId, offset);
        offset += 2;

        //消息类型
        Util.putByte(bytes, (byte) 0x20, offset);
        offset += 1;

        //消息类别
        Util.putByte(bytes, (byte) 0xF0, offset);
        offset += 1;

        //消息ID
        Util.putShort(bytes, (short) 0xb528, offset);
        offset += 2;

        //消息发送时间
        Date date = new Date();
        long second = date.getTime() / 1000;
        Util.putInt(bytes, (int) second, offset);
        offset += 4;

        Util.putInt(bytes, 0, offset);
        offset += 4;

        //消息发送序号
        Util.putShort(bytes, (short) 1, offset);
        offset += 2;

        //保留,默认0，6个字节
        offset += 6;

        //命令编号,暂时不填
        offset += 20;


        //模块MARK地址
        Util.putShort(bytes, markAddr, offset);
        offset += 2;

        //调显类型
        Util.putShort(bytes, displayType.getType(), offset);
        offset += 2;
        Util.putInt(bytes, 0xAAAAAAAA, offset);
        offset += 4;
        return bytes;
    }
}
